package com.itheima.arraylist;

import java.util.ArrayList;

public class ArrayListTest {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();
        User u1 = new User("001","zhangshan","123");
        User u2 = new User("002","lisi","123");
        User u3 = new User("003","wangwu","123");

        list.add(u1);
        list.add(u2);
        list.add(u3);

        boolean result = findUser("004", list);
        System.out.println(result);
    }

    public static boolean findUser(String id ,ArrayList<User> list){
        //1.遍历集合得到每一个用户
        for (int i = 0; i < list.size(); i++) {
            User u = list.get(i);
            String uId = u.getId();
            if (uId.equals(id)){
                return true;
            }
        }
        return false;
    }
}
